<template>
  <div class="warning-list">
    <titleBar titleText="预警" :hasBottomBorder="false" :noPadding="true">
      <div class="slot-nav">
        <tabs :tabs-arr="warningTabList"  :isNewTabs=true @returnIndex="getTabIndex" />
        <moreDropdownMenu :routerConfig="routerListCofig"></moreDropdownMenu>
      </div>
    </titleBar>
    <main>
      <div  v-if="tableData && tableData.length === 0" class="no-data">
        <img src="https://mt.heng-tai.com.cn/m-perfeval-pc/img/pc-other_zwsj_icon.4c654fe.png" alt="">
        <div>暂无数据</div>
      </div>
      <div class="editable-box"  v-if="tableData && tableData.length > 0">
        <el-editable
          v-loading="loading"
          class="table"
          ref="table"
         
          :data="tableData"
          :columns="tableColumn"
          :height="tableHeight"
        />
        <!-- 分页模块 -->
        <el-pagination
          class="pagination"
          align="right"
          style="margin-top:10px;"
          @size-change="sizeChange"
          @current-change="pageChange"
          :page-sizes="PAGE_NUMBER"
          :page-size="pageSize"
          :current-page="curPage"
          :layout="PAGINATION_LAYOUT"
          :total="totalElements"
        />
      </div>
    </main>
  </div>
</template>

<script>
import titleBar from '@/moduleComponents/newWorkbench/title-bar';
import moreDropdownMenu from '@/moduleComponents/newWorkbench/more-dropdown-menu';
import tabs from '@components/tabs/tabTool';
import ElEditable from '@components/el-editable/index.vue';
import { tableColumn, warningTabList, routerListCofig } from './const';
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common';
import {
  workbenchWarningMatterountNum,
  workbenchWarningNewList
} from '@const/mDataCenterApi.js';
export default {
  name: 'warningList',
  components: {
    moreDropdownMenu,
    ElEditable,
    titleBar,
    tabs
  },
  props: {
    tableHeight: {
      default: 100,
      type: Number
    }
  },
  data() {
    return {
      tabIndex: 0,
      type: '',
      loading: false,
      tableData: [],
      countList: [],
      tableColumn,
      warningTabList,
      routerListCofig,
      curPage: 1, // 当前页
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      pageSize: PAGE_NUMBER[0], // 一页的数量
      totalElements: 0 // 总共的条数
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // tab 切换
    getTabIndex(index) {
      this.curPage = 1;
      this.tabIndex = index;
      this.type = this.warningTabList[index].type || '';
      this.getData();
    },
    // 查询数据
    getData() {
      this.getTableCount();
      this.getTableList();
    },
    // 页码更改
    sizeChange(size) {
      this.pageSize = size;
      this.getTableList();
    },
    // 切换不一样的页面,重置一切数据
    pageChange(curPage) {
      this.curPage = curPage;
      this.getTableList();
    },
    // 查询数量
    getTableCount() {
      this.$axios({
        url: workbenchWarningMatterountNum,
        method: 'post'
      })
        .then(res => {
          if (res.data.code === '0') {
            this.countList = res.data.payload || [];
            this.getCountNumByCountList();
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 获取数量
    getCountNumByCountList() {
      this.warningTabList.forEach(inItem => {
        inItem.badgeValue = 0;
        this.countList.forEach(item => {
          if (inItem.type === item.type) {
            inItem.badgeValue =
              Number(item.typeNumber) > 99 ? '99+' : Number(item.typeNumber);
          }
        });
      });
    },
    // 查询列表数据
    getTableList() {
      this.loading = true;
      this.$axios({
        url: workbenchWarningNewList,
        method: 'post',
        data: {
          page: this.curPage,
          pageSize: this.pageSize,
          type: this.type
        }
      })
        .then(res => {
          this.tableData = res.data.payload.content || [];
          this.totalElements = res.data.payload.totalElements;
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
};
</script>

<style scoped lang="less">
.el-icon-more {
  font-size: 20px;
  cursor: pointer;
  height: 100%;
  margin: 0 8px 0 16px;
}
.slot-nav {
  margin-top: -1px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-image: linear-gradient(to right, #e6edff, #fff);
  /deep/ .tab-tool {
    background-color: transparent;
    header {
      background-color: transparent;
      height: 48px;
      div {
        line-height: 48px;
        font-size: 16px;
        color: #666666;
        position: relative;
      }
      div.active {
        color: #333333;
        font-size: 16px;
        font-weight: bold;
      }
      div.active::after {
        left: 10px;
        background: #4d84ff;
        width: calc(100% - 20px);
        height: 3px;
        border-radius: 100px;
      }
      .badge {
        top: -11px;
        right: 8px;
      }
      .el-badge__content {
        position: absolute;
        top: -11px;
      }
    }
  }
}
.warning-list {
  background-color: #fff;
  overflow: hidden;
  border-radius: 5px;
  .editable-box {
    border: 1px solid #e6e6e6;
    height: calc(100% - 50px);
    position: relative;
    overflow: hidden;
    border-radius: 3px;
  }
  .pagination {
    position: absolute;
    right: 0;
    bottom: 9px;
    width: 100%;
    padding-top: 9px;
    padding-right: 15px;
  }
  /deep/ .el-table--border,
  .el-table--group {
    border: none;
  }
  /deep/ .table {
    margin-right: -1px;
    .el-table--border th:nth-last-child(2) {
      border-right: none;
    }
    .el-table td,
    .el-table th {
      padding: 7px 0;
    }
  }
}
.warning-list main {
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  .total {
    display: inline-block;
    padding: 8px 0;
  }
  .no-data {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 80%;
    font-size: 14px;
    color: #999999;
    img {
      width: 172px;
      height: 100px;
      margin-bottom: 17px;
    }
  }
}
</style>
